using System;
using System.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using GeroByte.Data.SqlClient;

public partial class Movimentos_DespesaInsert : Page
{
    #region Constants

    private const string CONNECTION_STRING = "AcademiaConnectionString";

    #endregion

    #region Methods

    #region EventHandlers

    protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected void frmDespesaMain_ItemInserted(object sender, FormViewInsertedEventArgs e)
    {
        try
        {
            string sqlCommand = "Select Top 1 PessoaDespesaID From PessoaDespesa Where PessoaID = " +
                                cbPessoa.SelectedItem.Value + " Order By PessoaDespesaID Desc";
            string selecionados =
                SqlDataManager.ExecuteScalar(sqlCommand,
                                             ConfigurationManager.ConnectionStrings[CONNECTION_STRING].ConnectionString)
                    .ToString();
            var chkRecibo = (CheckBox) frmDespesaMain.FindControl("chkRecibo");
            var chkPago = (CheckBox) frmDespesaMain.FindControl("chkPago");
            if (chkRecibo.Checked && chkPago.Checked)
            {
                string scriptPopup =
                    @"
            					<script>
            					<!--
            						openWindow('../Relatorios/Recibo.aspx?recibos=" +
                    selecionados + @"&pessoaID=" + cbPessoa.SelectedItem.Value +
                    @"',350,300);
            					-->
            					</script>";
                if (!Page.ClientScript.IsClientScriptBlockRegistered("imprimeRecibo"))
                    Page.RegisterClientScriptBlock("imprimeRecibo", scriptPopup);
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

    #endregion

    #endregion
}